package com.xiaoyi.condition;

import com.xiaoyi.type.TypeHandler;
import com.xiaoyi.type.TypeHandlerRegistry;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author xiaoyi
 * @version 1.0.0
 * @createTime 2023-02-20 22:19:00
 */
public class EqContition extends AbstractCondition {
    @Override
    public ConditionModel doCondition(Map<String, Object> map) {
        ConditionModel conditionModel = new ConditionModel();
        StringBuilder sb = new StringBuilder();
        sb.append(" ");
        map.forEach((k, v) -> {
            if (Objects.nonNull(v)) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append(" and ");
                stringBuilder.append(k);
                stringBuilder.append(" = ");
                stringBuilder.append("?");
                if (String.class.equals(v.getClass())) {
                    conditionModel.addParam(String.valueOf(v));
                } else {
                    conditionModel.addParam(v);
                }
                sb.append(stringBuilder.toString());
                sb.append(" ");
            }
        });
        sb.append(" ");
        conditionModel.setSql(sb.toString());
        return conditionModel;
    }







}
